import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import cookie from '@/common/js/cookie'
import {queue} from './zzdmd'
import Vant from 'vant';
import axios from 'axios'
import 'vant/lib/index.css';

Vue.use(Vant);
Vue.config.productionTip = false
Vue.prototype.$axios = axios 
Vue.prototype.$cookie = cookie

router.beforeEach((to, from, next)=>{
  let token = cookie.get(process.env.VUE_APP_BASE_TOKEN);
  if(token){
    axios.defaults.headers.common['token'] = token;
  }
  if(to.meta.title){
		document.title = to.meta.title
	}
queue(store.getters.lastName, store.getters.accountId)
next()
})


axios.interceptors.response.use(function (response) {
  if(response.data.result == 2){
    cookie.delete(process.env.VUE_APP_BASE_TOKEN);
    setTimeout(function(){
      router.replace('/')
    },1000)
  }
  return response;

}, function (error) {
  return Promise.reject(error);
});
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
